using System;
using System.Collections.Generic;
using System.Text;

namespace PowerStructure
{
   [Serializable]
   public class FixedCapacityQueue<T> : Queue<T>
   {
      public FixedCapacityQueue() : base() { }
      public FixedCapacityQueue(IEnumerable<T> collection) : base() { }
      public FixedCapacityQueue(int capacity) : base() { _lockCapacity = capacity; }

      private int _lockCapacity;
      public int LockCapacity
      {
         get { return _lockCapacity; }
         set
         {
            _lockCapacity = value;
            for (int i = base.Count; i > _lockCapacity; i--)
            {
               base.Dequeue();
            }
            base.TrimExcess();
         }
      }

      public new void Enqueue(T item)
      {
         if (base.Count == _lockCapacity)
            base.Dequeue();
         base.Enqueue(item);
      }
   }
}
